
$(document).ready(function() {
	
			/**
			 * 左边导航菜单
			 */
	$(".nav-list").on("click",function(h) {
		var g = $(h.target).closest("a");
		if (!g || g.length == 0) {
			return
		}
		c = $("#sidebar").hasClass("menu-min");
		if (!g.hasClass("dropdown-toggle")) {
			if (c && ace.click_event == "tap" && g.get(0).parentNode.parentNode == this) {
				var i = g.find(".menu-text").get(0);
				if (h.target != i && !a.contains(i, h.target)) {
					return false
				}
			}
			return

		}
		var f = g.next().get(0);
		if (!$(f).is(":visible")) {
			var d = $(f.parentNode).closest("ul");
			if (c && d.hasClass("nav-list")) {
				return
			}
			d.find("> .open > .submenu").each(function() {
				if (this != f && !$(this.parentNode).hasClass("active")) {
					$(this).slideUp(200).parent().removeClass("open");
				}
			})
		} else {}
		if (c && $(f.parentNode.parentNode).hasClass("nav-list")) {
			return false
		}
		$(f).slideToggle(200).parent().toggleClass("open");
		return false
	});
	/**
	 * 搜索表单提交按enter搜索功能，form需要加上class="search-form" 搜索按钮的需包含id="search-btn"
	 */
	$("form.search-form").attr("onsubmit","return false").keydown(function(event){
	    if(event.keyCode == 13) {
	    	golbal.search($(this).find("button[id='search-btn']"));
	  		event.preventDefault ? event.preventDefault() : (event.returnValue = false);
	    }
	});
	$("#clear-search-form-btn,.clear-search-form-btn").click(function(){
		var $form = $(this).parents("form.search-form");
		$form.form("clear");
		golbal.search($(this));
	});
});
/**
 * 日期格式化函数
 * 
 * @param format
 *            格式化字符串
 * @returns 格式化以后的日期字符串
 */
Date.prototype.format = function(format) // author: meizz
{
	var o = {
		"M+": this.getMonth() + 1,
		// month
		"d+": this.getDate(),
		// day
		"h+": this.getHours(),
		// hour
		"m+": this.getMinutes(),
		// minute
		"s+": this.getSeconds(),
		// second
		"q+": Math.floor((this.getMonth() + 3) / 3),
		// quarter
		"S": this.getMilliseconds()
		// millisecond
	}
	if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o) if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
	return format;
}
/**
 * form表单数据转换成json
 */
$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a,function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};
/**
 * form表单数据转换成String
 */
$.fn.serializeString = function(){
	var str = "?1=1";
	var a = this.serializeArray();
	$.each(a,function() {
		var val = "&"+this.name+"="+encodeURI(this.value);
		str+=val;
	});
	return str;
}
$.extend($.fn.tabs.methods, {   
    /**
     * 加载iframe内容  
     * @param  {jq Object} jq     [description]  
     * @param  {Object} params    params.which:tab的标题或者index;params.iframe:iframe的相关参数  
     * @return {jq Object}        [description]  
     */  
    loadTabIframe:function(jq,params){   
        return jq.each(function(){   
            var $tab = $(this).tabs('getTab',params.which);   
            if($tab==null) return;   
  
            var $tabBody = $tab.panel('body');   
  
            //销毁已有的iframe   
            var $frame=$('iframe', $tabBody);   
            if($frame.length>0){   
                try{//跨域会拒绝访问，这里处理掉该异常   
                    $frame[0].contentWindow.document.write('');   
                    $frame[0].contentWindow.close();   
                }catch(e){   
                    //Do nothing   
                }   
                $frame.remove();   
                
            }   
            $tabBody.html('');   
  
            $tabBody.css({'overflow':'hidden','position':'relative'});   
            var $mask = $('<div style="position:absolute;z-index:2;width:100%;height:100%;background:#ccc;z-index:1000;opacity:0.3;filter:alpha(opacity=30);"><div>').appendTo($tabBody);   
            var $maskMessage = $('<div class="mask-message" style="z-index:3;width:auto;height:35px;line-height:35px;position:absolute;top:50%;left:50%;padding: 0px 5px 10px 40px;background:url(/resources/images/loading-0.gif) no-repeat scroll 0px center;">' + (params.iframe.message || '加载中...') + '</div>').appendTo($tabBody);   
            var $containterMask = $('<div style="position:absolute;width:100%;height:100%;z-index:1;background:#fff;"></div>').appendTo($tabBody);   
            var $containter = $('<div style="position:absolute;width:100%;height:100%;z-index:0;"></div>').appendTo($tabBody);   
  
            var iframe = document.createElement("iframe");   
            iframe.src = params.iframe.src;   
            iframe.frameBorder = params.iframe.frameBorder || 0;   
            iframe.height = params.iframe.height || '100%';   
            iframe.width = params.iframe.width || '100%';   
            if (iframe.attachEvent){   
                iframe.attachEvent("onload", function(){   
                    $([$mask[0],$maskMessage[0]]).fadeOut(params.iframe.delay || 'slow',function(){   
                        $(this).remove();   
                        if($(this).hasClass('mask-message')){   
                            $containterMask.fadeOut(params.iframe.delay || 'slow',function(){   
                                $(this).remove();   
                            });   
                        }   
                    });   
                });   
            } else {   
                iframe.onload = function(){   
                    $([$mask[0],$maskMessage[0]]).fadeOut(params.iframe.delay || 'slow',function(){   
                        $(this).remove();   
                        if($(this).hasClass('mask-message')){   
                            $containterMask.fadeOut(params.iframe.delay || 'slow',function(){   
                                $(this).remove();   
                            });   
                        }   
                    });   
                };   
            }   
            $containter[0].appendChild(iframe);   
        });   
    },   
    /**
     * 增加iframe模式的标签页  
     * @param {[type]} jq     [description]  
     * @param {[type]} params [description]  
     */  
    addIframeTab:function(jq,params){   
        return jq.each(function(){   
            if(params.tab.href){   
                delete params.tab.href;   
            }   
            $(this).tabs('add',params.tab);   
            $(this).tabs('loadTabIframe',{'which':params.tab.title,'iframe':params.iframe});   
        });   
    },   
    /**
     * 更新tab的iframe内容  
     * @param  {jq Object} jq     [description]  
     * @param  {Object} params [description]  
     * @return {jq Object}        [description]  
     */  
    updateIframeTab:function(jq,params){   
        return jq.each(function(){   
            params.iframe = params.iframe || {};   
            if(!params.iframe.src){   
                var $tab = $(this).tabs('getTab',params.which);   
                if($tab==null) return;   
                var $tabBody = $tab.panel('body');   
                var $iframe = $tabBody.find('iframe');   
                if($iframe.length===0) return;   
                $.extend(params.iframe,{'src':params.iframe.src||$iframe.attr('src')});   
            }   
            $(this).tabs('loadTabIframe',params);   
        });   
    }   
}); 
 